package tech.aistar.wyymusicplayer.mapper;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tech.aistar.wyymusicplayer.pojo.Song;

import java.util.List;

public interface SongMapper {

    // SongMapper.java
        // 新增歌曲元数据
//        int insertSong(Song song);

        // 根据 ID 查询歌曲信息
        @Select("select * from songs where song_id = #{songId}")
        Song selectById(Integer songId);

        // 根据 ID 查询歌曲信息
        @Select("select * from songs where song_id = #{value}")
        Song findById(Integer songId);

        // 根据标题模糊查询歌曲
        @Select("select * from songs where title like CONCAT('%',#{value},'%')")
        List<Song> selectByTitle(String title);

        // 根据艺术家查询歌曲
        @Select("select * from songs where artist = #{value}")
        List<Song> selectByArtist(String artist);

        // 更新歌曲元数据
//        int updateSong(Song song);

        // 删除歌曲记录
//        int deleteById(int songId);

        @Select({
                "<script>",
                "SELECT * FROM songs",
                "WHERE song_id IN",
                "<foreach item='id' collection='ids' open='(' separator=',' close=')'>",
                "#{id}",
                "</foreach>",
                "</script>"
        })
        List<Song> selectSongsByIds(@Param("ids") List<Integer> ids);

}

